package com.sailfish.springbootdemo.dao.db7;


import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowProcessRecords;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TbFlowProcessRecordsDao {

    @Select("<script> " +
            "SELECT flow_no, flow_approver, flow_level " +
            "FROM " + DB7TableName.TB_FLOW_PROCESS_RECORDS +
            " WHERE 1=1 " +
            "<if test='flowNoList != null and !flowNoList.isEmpty()'>" +
            " AND flow_no IN " +
            "<foreach collection='flowNoList' item='flowNo' open='(' separator=',' close=')'> " +
            "#{flowNo} " +
            "</foreach> " +
            "</if>" +
            " AND flow_name = '工艺设计人员'" +
            "</script>")
    List<TbFlowProcessRecords> getFlowRecordsByFlowNo(@Param("flowNoList") List<String> flowNoList);

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_PROCESS_RECORDS +
            " where 1=1" +
            "<if test='flow_no != null and flow_no!=\"\"'>" +
            " and flow_no = #{flow_no}" +
            "</if>" +
            "<if test='flow_type != null and flow_type!=\"\"'>" +
            " and flow_type = #{flow_type}" +
            "</if>" +
            " order by flow_no asc, create_time asc,seq asc" +
            "</script>")
    List<TbFlowProcessRecords> getTbFlowProcessRecordsList(TbFlowProcessRecords tbFlowProcessRecords);

    @Select("<script> " +
            "select \n" +
            "*" +
            " from " + DB7TableName.TB_FLOW_PROCESS_RECORDS +
            " where 1=1" +
            "<if test='flowNo != null and flowNo!=\"\"'>" +
            " and flow_no = #{flowNo}" +
            "</if>" +
            " and flow_name = '工艺设计人员'" +
            "</script>")
    List<TbFlowProcessRecords> getRecordByFlowNo(@Param("flowNo") String flowNo);

    @Select("<script> " +
            "select \n" +
            " distinct flow_no" +
            " from " + DB7TableName.TB_FLOW_PROCESS_RECORDS +
            " where 1=1" +
            "<if test='userId != null and userId!=\"\"'>" +
            " and flow_approver = #{userId}" +
            "</if>" +
            " and flow_name = '工艺设计人员'" +
            " and flow_level is not null and flow_level = 1" +
            "</script>")
    List<String> getRecordByApproveUser(@Param("userId") String userId);

    @Insert("insert into " + DB7TableName.TB_FLOW_PROCESS_RECORDS + " " +
            "(" +
            "flow_no," +
            "flow_type, " +
            "flow_name, " +
            "flow_level, " +
            "flow_approver, " +
            "result, " +
            "remark, " +
            //"seq" +
            "create_time," +
            "create_user" +
            ") "+
            "values "+
            "(" +
            "#{flow_no}, " +
            "#{flow_type}, " +
            "#{flow_name}, " +
            "#{flow_level}, " +
            "#{flow_approver}, " +
            "#{result}, " +
            "#{remark}, " +
            //"#{seq}," +
            "#{create_time}," +
            "#{create_user}" +
            ")"
    )
    Integer insertFlowProcessRecords(TbFlowProcessRecords tbFlowProcessRecords);


    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_PROCESS_RECORDS +
            " where flow_no=#{flowNo}"+
            "</script>")
    Integer deleteFlowProcessRecordsByFlowNo(@Param("flowNo")String flowNo);
}
